<?php

namespace App\Http\Resources\App;

use Illuminate\Http\Resources\Json\JsonResource;

class WorkDetailResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
//        dd($this->users[0]->pivot);
        return ['question' => $this->question, 'id' => $this->id, 'description' => $this->description, 'type' => $this->type, $this->mergeWhen($this->whenLoaded('users'), ['user_result' => $this->users[0]->pivot->result ?? null, 'mark' => $this->users[0]->pivot->review['mark'] ?? null])
            , $this->mergeWhen($this->type != 3, ['selections' => $this->data['selections'] ?? []])];
    }
}
